// 入口
import 'package:flutter_learn/oop_learn.dart';

void main() {
  Cache<String> cache1 = Cache();
  cache1.setItem('cache1', 'cache1 value');
  String? string1 = cache1.getItem('cache1');
  print('string $string1');

  Cache<int> cache2 = Cache();
  cache2.setItem('cache2', 888);
  int? int1 = cache2.getItem('cache2');
  print('int $int1');

  Member<Student> member = Member(Student('清华', 'zhang', 22));
  print(member.fixedName());
}

// 泛型
class Cache<T> {
  final Map<String, T> _cached = {};
  void setItem(String key, T value) {
    _cached[key] = value;
  }

  // 泛型方法
  T? getItem(String key) {
    return _cached[key];
  }
}

class Member<T extends Person> {
  final T _person;
  // 泛型作用 约束参数类型
  Member(this._person);

  String fixedName() {
    return 'fixed:${_person.name}';
  }
}
